home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
boe.pres.k12.wv.us
/
boe.pres.k12.wv.us.zip
/
boe.pres.k12.wv.us
/
Utilities
/
Xerox Workcentre 5335
/
Windows Scan
/
32-bit_x86
/
Francais
/
cpsimage.cab
/
data
/
sys
/
argTokenClass.elf
next >
Wrap
Text File
|
2009-03-16
|
9KB
|
246 lines
/* $Id: argTokenClass.elf,v 1.7 2009/02/06 15:48:02 campanel Exp $ */
#load "sys/lang.elf";
/*****************************************************************************/
/*
** This class can be used to encode and decode arguements into strings
*/
/* @New
Creates an instance of a ARGTOKEN class for manipulation of string parameters.
This is a convention that defines an arguement as a string with keyword|type|value.
Keyword may be any alpha-numeric string. Type is one of: b, d, i, s, or l where l is
followed by one of the first 4 types. Value is a STRING that will be converted to
the given data type. In the case of a list the elements are comma separated.
An example of a list of integers could be "window|li|0,0,100,200". To construct this
class with the given example use:
ARGTOKEN atk = new (ARGTOKEN, param: "window|li|0,0,100,200");
This CLASS is useful when a script is invoked with a long string of several paramters
encoded in semicolon separated paramters. See also ARGTOKENPARSE.
*/
/* @toString Convert this class to a STRING*/
/* @getKey Return the keyword of this paramter */
/* @getType Return the character that indicates the base data type
(b=BOOLEAN,i=INTEGER,d=DOUBLE,s=STRING,lx=LIST where x is a data type).
*/
/* @getValue Return the actual data value as an object. */
/*****************************************************************************/
CLASS ARGTOKEN
{
METHOD New (STRING param) {
LIST allTokens = param.split( delims: "|" );
if (allTokens.length() == 3) {
this.baseString = param;
this.keyword = allTokens[0];
this.dataType = allTokens[1];
if ((this.dataType.length() > 1) &&
(this.dataType.index(val:0).strcasecmp(str: "l")) )
{
LIST allList = allTokens[2].split( delims: ",");
INTEGER i;
OBJECT tmp;
for (i=0; i<allList.length(); i++) {
/* temporary use of class data field */
tmp = this.pushData(t: this.dataType[1], d: allList[i]);
this.dL.insert(entry: i, obj: tmp);
}
} else {
this.pushData(t: this.dataType, d: allTokens[2]);
}
}
}
METHOD toString ( ) RETURNS ( STRING param) {
param = this.baseString;
}
METHOD getKey ( ) RETURNS ( STRING keyword )
{
keyword = this.keyword;
}
METHOD getType ( ) RETURNS ( STRING dtype )
{
dtype = this.dataType;
}
METHOD getValue ( ) RETURNS ( OBJECT dvalue )
{
if (this.dataType.strcasecmp( str: "b" )) {
dvalue = this.dB;
return;
}
if (this.dataType.strcasecmp( str: "i" )) {
dvalue = this.dI;
return;
}
if (this.dataType.strcasecmp( str: "d" )) {
dvalue = this.dD;
return;
}
if (this.dataType.strcasecmp( str: "s" )) {
dvalue = this.dS;
return;
}
if (this.dL) {
dvalue = this.dL;
return;
}
}
/*****************************************************************************
******************** Any Private Methods? ******************************
*****************************************************************************/
private METHOD pushData( STRING t, STRING d)
RETURNS( OBJECT oby)
{
if (t.strcasecmp( str: "b" )) {
if (d.strcasecmp(str: "false") ||
d.strcasecmp(str: "0") )
{
this.dB = FALSE;
} else {
this.dB = TRUE;
}
oby = this.dB;
}
else if (t.strcasecmp( str: "i" )) {
this.dI = d;
oby = this.dI;
}
else if (t.strcasecmp( str: "d" )) {
this.dD = d;
oby = this.dD;
}
else if (t.strcasecmp( str: "s" )) {
this.dS = d;
oby = this.dS;
}
}
/*****************************************************************************
******************** Internal Data Fields ******************************
*****************************************************************************/
STRING baseString;
STRING keyword;
STRING dataType;
BOOLEAN dB;
INTEGER dI;
DOUBLE dD;
STRING dS;
LIST dL;
}
/*****************************************************************************/
/*
** This class can be used to parse a semicolon separated set of parameters into
** a LIST of ARGTOKENS
*/
/* @New
Creates an instance of a ARGTOKENPARSE class based on a given semicolon separated parmeter
STRING and holds a LIST of ARGTOKEN objects for script reference. An example construction
of this class with 3 ARGTOKEN objects:
STRING myargs = "method|s|rotate;iangle|i|90;nomask|b|1";
ARGTOKENPARSE atkp = new (ARGTOKENPARSE, argList: myargs);
This CLASS is useful when a script requires a complex, variable list of imports
that are better left "free form".
*/
/* @toString Convert this class to a STRING*/
/* @getList Return the LIST of ARGTOKENs made from the arglist */
/* @invokeListOnObject
Use object list of ARGTOKENs to invoke a method of the given object obj. Assumes the
argList used to create this object follows a convention of methods and method
paramters as:
method|s|methName;paramName|?|values...
Where the keyword method indicates the actual method, the paramName is the actual
name of the paramter and the actual value is given. Several methods may be invoked.
For example, given an XIPIMAGE the following will invoke rotate and invert:
method|s|rotate;iangle|i|90;nomask|b|TRUE;method|s|invert
The results of the last method call are returned.
*/
/*****************************************************************************/
CLASS ARGTOKENPARSE
{
METHOD New (STRING argList) {
LIST allTokens = argList.split( delims: ";" );
if (allTokens.length() > 0) {
INTEGER i;
ARGTOKEN curAT;
for (i=0; i<allTokens.length(); i++) {
if (allTokens[i].length() > 0) {
curAT = new(ARGTOKEN, param: allTokens[i]);
this.ags.insert(entry: i, obj: curAT);
}
}
}
}
METHOD getList ( ) RETURNS ( LIST atl )
{
atl = this.ags;
}
METHOD invokeListOnObject(OBJECT obj)
RETURNS (BOOLEAN executed, LIST result)
{
executed = FALSE;
if ((!obj) || (!this.ags))
return;
CLASSREF cr = new(CLASSREF, handle: obj);
//if (!cr) return;
INTEGER ii;
INTEGER jj;
INTEGER pCnt;
INTEGER tokLen = this.ags.length();
ARGTOKEN argM;
STRING methodName;
LIST paramList;
for(ii=0; ii<tokLen; ii++) {
argM = this.ags[ii];
methodName = argM.getValue();
/* look ahead to count paramters */
pCnt = 0;
for (jj=ii+1; jj<tokLen; jj++) {
if (this.ags[jj].getKey().strcasecmp(str:"method")) {
jj = tokLen+1;
} else {
pCnt = pCnt+1;
}
}
/* Put the paramters onto the call list & advance list pointer - ii*/
paramList.clear();
for (jj=1; jj<=pCnt; jj++) {
paramList.insert(name: this.ags[jj+ii].getKey(),
obj: this.ags[jj+ii].getValue() );
}
ii = ii+pCnt;
/* Invoke it! */
if ( cr.hasMethod(name: methodName) ) {
result = cr.invokeMethod(name: methodName, params: paramList);
executed = TRUE;
}
}
}
/*****************************************************************************
******************** Internal Data Fields ******************************
*****************************************************************************/
STRING baseString;
LIST ags;
}